package com.codejob.portal.web.action.job;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.codejob.portal.dao.utils.Page;
import com.codejob.portal.entity.job.Careers;
import com.codejob.portal.services.impl.job.CareersManager;
import com.codejob.portal.services.intf.BusinessExcption;
import com.codejob.portal.web.BaseModelAction;

@Namespace("/job")
public class CareersAction  extends BaseModelAction<Careers>  {
	private static final long serialVersionUID = -6760475485644390099L;

	private Long id;
	
	private Careers careers;
	
	private Page<Careers> page=new Page<Careers>(5);
	@Autowired
	private CareersManager careersManager;
	
	public String jobIndex(){
		//设置默认排序方式
		if (page!=null&&!page.isOrderBySetted()) {
			page.setOrderBy("id");
			page.setOrder(Page.DESC);
		}
		page=careersManager.careersPage(page);
		return "jobIndex";
	}
	
	public String look(){
		try {
			careersManager.look(id);
		} catch (BusinessExcption e) {
			e.printStackTrace();
		}
		return "look";
	}
	
	public String prepareCreate(){
		if(!isLogin()){
			return "login";
		}
		return "createCareers";
	}
	
	public String createCareers(){
		if(!isLogin()){
			return "login";
		}
		try {
			careersManager.createCareers(careers,this.getUserId());
		} catch (BusinessExcption e) {
			e.printStackTrace();
		}
		return "createSuccess";
	}
	
	public String prepareUpdate(){
		if(!isLogin()){
			return "login";
		}
		return "updateCareers";
	}
	
	public String updateCareers(){
		if(!isLogin()){
			return "login";
		}
		try {
			careersManager.updateCareers(careers);
		} catch (BusinessExcption e) {
			e.printStackTrace();
		}
		return "updateSuccess";
	}
	
	@Override
	public Careers getModel() {
		return careers;
	}
	@Override
	public void prepare()  {
		if (id != null) {
			careers = careersManager.get(id);
		}
		if (careers == null) {
			careers = new Careers();
		}
		
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Careers getCareers() {
		return careers;
	}
	public void setCareers(Careers careers) {
		this.careers = careers;
	}

	public Page<Careers> getPage() {
		return page;
	}
	public void setPage(Page<Careers> page) {
		this.page = page;
	}

	
}
